#include<bits/stdc++.h>
using namespace std;
int solve() {
  int n;cin>>n;
  vector<pair<int,int>> v(n);
  for(auto&[ed,st]:v) cin>>st>>ed;
  sort(v.begin(),v.end());

  int ans=0,now=0; // Current time, to solve the problem in O(n) time;
  for(auto&[ed,st]:v) {
    if(st>=now) {
      ans++;
      now = ed;
    }
  }
  cout<<ans<<"\n";
  return 0;
}
int main() {
  solve();
  return 0;
}
